package com.com.knowledgepaymentmanagementsystem.controller.course;

import com.com.knowledgepaymentmanagementsystem.pojo.course.Audio;
import com.com.knowledgepaymentmanagementsystem.service.course.AudioService;
import com.com.knowledgepaymentmanagementsystem.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张攀
 * @version 1.0
 * @description: TODO
 * @date 2025/9/22 下午4:45
 */

@Api(tags = "音频管理")
@RestController
@CrossOrigin
@RequestMapping("/audio")
public class AudioController {

    @Autowired
    private AudioService audioService;


    @ApiOperation(value = "查询音频",httpMethod = "POST",notes = "查询音频")
    @PostMapping("/find")
    public ResultUtil<List<Audio>> getAudio(@RequestBody Audio audio){
        try {
            return new ResultUtil<>(200, "查询音频数据成功", audioService.findAduioList(audio));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "查询音频数据失败");
        }
    }
    @ApiOperation(value = "新增音频课程",httpMethod = "POST",notes = "新增音频课程")
    @PostMapping("insert")
    public ResultUtil insertAudios(@RequestBody Audio audio){
        try {
            return new ResultUtil<>(200,"新增成功",audioService.insertAudios(audio));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"新增失败");
        }
    }

    @ApiOperation(value = "修改音频课程",httpMethod = "PUT",notes = "修改音频课程")
    @PutMapping("/update")
    public ResultUtil updateAudios(@RequestBody Audio audio){

        audioService.updateAudios(audio);
        try {
            return new ResultUtil(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"修改失败");

        }
    }

    @ApiOperation(value = "删除音频课程",httpMethod = "DELETE",notes = "删除音频课程")
    @DeleteMapping("/delete")
    public ResultUtil deleteAudios(Integer id){
        audioService.deleteAudios(id);
        try {
            return new ResultUtil(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"删除失败");

        }
    }
}
